//按钮事件新增或编辑
var B36EAD_type = "";
//其他页面传到本页面参数
var B36EAD_param = {};
//暂时没用
var B36EAD_validate = "";
//当前触发按钮
var B36EAD_btn = "";

/*定义下拉框集合定义*/
/*declare select options begin*/

/*declare select options end*/

//主从表传递参数
function B36EAD_param_set(){
	/*Main Subsuv Table Param Begin*/
	if(B36EAD_param.hasOwnProperty("P_ID"))
 		$("#B36EAD_P_ID").val(B36EAD_param["P_ID"]);
   if(B36EAD_param.hasOwnProperty("P_ID_cn_name"))
       $("#B36EAD_P_ID_cn_name").val(B36EAD_param["P_ID_cn_name"]);
	
	/*Main Subsuv Table Param end*/
}

//业务逻辑数据开始
function B36EAD_test_trade_biz_start(inputdata) {
	B36EAD_param = inputdata;
	layer.close(ly_index);
    /*biz begin*/
    B36EAD_init_test_trade()
	
    /*biz end*/
}

/*biz step begin*/

/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

function B36EAD_TRADE_FILE_cn_name_fun(){
    B36EAD_btn = "TRADE_FILE"
    index_subhtml = "t_sys_file2.vue";
    random_subhtml = "A088FR";
    if(loadHtmlSubVueFun("sys_vue/t_sys_file2.vue","B36EAD_test_trade_call_vue") == true){
        var n = Get_RandomDiv("A088FR","");
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                $('#A088FR_t_sys_file_Events').bootstrapTable('resetView');
                A088FR_param["ly_index"] = index;
                A088FR_param["target_name"] = "B36EAD_find_"+B36EAD_btn+"_cn_name";
                A088FR_param["target_id"] = "B36EAD_"+B36EAD_btn;
                A088FR_param["sourc_id"] = "MAIN_ID";
                A088FR_param["sourc_name"] = "NEW_FILE_NAME";
            },
            end: function(){
                $(n).hide();
            }
        });
     }
}

/*find qry fun end*/

/*页面结束*/
function B36EAD_page_end(){
	if(B36EAD_param["type"] == "edit"){
		B36EAD_get_edit_info();
	}
}

//页面初始化方法
function B36EAD_init_test_trade() {
	//type = getUrlParam("type");
	B36EAD_param_set();
	if(B36EAD_param["type"] == "add"){
//		$("#B36EAD_main_id").parent().parent().parent().hide();
		
		/*父页面查询条件参数传递至子页面并赋值*/
		/*Get Find Select param bgein*/
		
		/*Get Find Select param end*/	
	}
	else if(B36EAD_param["type"] == "edit"){
	
	}
	
	//表单验证
	B36EAD_checkFormInput();
	/*时间格式初始化*/
	/*form datetime init begin*/
	
    /*form datetime init end*/
	
	B36EAD_page_end();
}

//提交表单数据
function B36EAD_SubmitForm(){
	if(B36EAD_param["type"] == "add"){
		var inputdata = {
				"param_name": "N01_ins_test_trade",
				"session_id": session_id,
				"login_id": login_id
	            /*insert param begin*/
                ,"param_value1": $("#B36EAD_P_ID").val()
                ,"param_value2": s_encode($("#B36EAD_TRADE_NAME").val())
                ,"param_value3": s_encode($("#B36EAD_TRADE_CODE").val())
                ,"param_value4": s_encode($("#B36EAD_TRADE_FILE").val())
				
	            /*insert param end*/
			};
		get_ajax_baseurl(inputdata, "B36EAD_get_N01_ins_test_trade");
	}
	else if(B36EAD_param["type"] == "edit"){
		var inputdata = {
				"param_name": "N01_upd_test_trade",
				"session_id": session_id,
				"login_id": login_id
	            /*update param begin*/
                ,"param_value1": $("#B36EAD_P_ID").val()
                ,"param_value2": s_encode($("#B36EAD_TRADE_NAME").val())
                ,"param_value3": s_encode($("#B36EAD_TRADE_CODE").val())
                ,"param_value4": s_encode($("#B36EAD_TRADE_FILE").val())
                ,"param_value5": $("#B36EAD_MAIN_ID").val()
				
	            /*update param end*/
			};
		get_ajax_baseurl(inputdata, "B36EAD_get_N01_upd_test_trade");
	}
}

//vue回调
function B36EAD_test_trade_call_vue(objResult){
	if(index_subhtml == "XXXXXX")
	{
		
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
    else if(index_subhtml == "t_sys_file2.vue"){
        var n = Get_RandomDiv("A088FR",objResult);
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                var inputdata = {
                    "type":B36EAD_type,
                    "ly_index":index,
                    "target_name":"B36EAD_find_TRADE_FILE_cn_name",
                    "target_id":"B36EAD_TRADE_FILE",
                    "sourc_id":"MAIN_ID",
                    "sourc_name":"NEW_FILE_NAME"
                };
                loadScript_hasparam("sys_vue/t_sys_file2.js","A088FR_t_sys_file2_biz_start",inputdata);
            },
            end: function(){
                $(n).hide();
            }
        });
    }
	
	/*get find subvue end*/
}

//for表单提交
$("#B36EAD_save_test_trade_Edit").click(function () {
	$("form[name='B36EAD_DataModal']").submit();
})

/*修改数据*/
function B36EAD_get_N01_upd_test_trade(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_upd_test_trade) == true)
	{
		swal("修改数据成功!", "", "success");
		A36EAD_test_trade_query();
		B36EAD_clear_validate();
		layer.close(B36EAD_param["ly_index"]);
	}
}

/*添加数据*/
function B36EAD_get_N01_ins_test_trade(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_ins_test_trade) == true)
	{
		swal("添加数据成功!", "", "success");
		A36EAD_test_trade_query();
		B36EAD_clear_validate();
		layer.close(B36EAD_param["ly_index"]);
	}
}

//取消编辑
$("#B36EAD_cancel_test_trade_Edit").click(function () {
	layer.close(B36EAD_param["ly_index"]);
	B36EAD_clear_validate();
	$("[id^='B36EAD_div']").hide();
})

//清除查找框
function B36EAD_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//清除验证缓存
function B36EAD_clear_validate(){
	$("#B36EAD_DataModal").find(".has-error").each(function(){
		$(this).removeClass('has-error');
	});
	$("#B36EAD_DataModal").find(".has-success").each(function(){
	 	$(this).removeClass('has-success');
	});
	$("#B36EAD_DataModal").find(".glyphicon").each(function(){
	 	$(this).remove();
	});
}

//输入框重置
function B36EAD_clear_edit_info(){
	var inputs = $("#B36EAD_DataModal").find('input');
	var selects = $("#B36EAD_DataModal").find("select");
	var textareas = $("#B36EAD_DataModal").find('textarea');
	var divs = $("div[id^='B36EAD'][id$='FILE_div']"); 
	$.each(inputs, function (i, obj) {
		$(obj).val("");
	});
	$.each(selects, function (i, obj) {
		$(obj).val("");
	});
	$.each(textareas, function (i, obj) {
		$(obj).val("");
	});
	$.each(divs, function (i, obj) {
		$(obj).html("");
	});
	
	/*清除输入框验证信息*/
	/*input validate clear begin*/
	
	/*input validate clear end*/
	B36EAD_init_test_trade();
}

//页面输入框赋值
function B36EAD_get_edit_info(){
	var rowData = $("#A36EAD_test_trade_Events").bootstrapTable('getData')[A36EAD_select_test_trade_rowId];
	var inputs = $("#B36EAD_DataModal").find('input');
	var selects = $("#B36EAD_DataModal").find("select");
	var textareas = $("#B36EAD_DataModal").find('textarea');
	
	//通用子页面输入框赋值
	Com_edit_info(rowData,inputs,selects,textareas,"A36EAD","B36EAD");
	
	/*文件附件格式*/
	/*input param fileinfo begin*/
	
	/*input param fileinfo end*/
}

//form验证
function B36EAD_checkFormInput() {
    B36EAD_validate = $("#B36EAD_DataModal").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        rules: {
        	/*input check rules begin*/
            B36EAD_MAIN_ID: {}
            ,B36EAD_P_ID: {digits: true,required : true,maxlength:10}
            ,B36EAD_TRADE_NAME: {maxlength:50}
            ,B36EAD_TRADE_CODE: {maxlength:50}
            ,B36EAD_TRADE_FILE: {maxlength:50}
			
            /*input check rules end*/
        },
        messages: {
        	/*input check messages begin*/
            B36EAD_MAIN_ID: {}
            ,B36EAD_P_ID: {digits: "必须输入整数",required : "必须输入整数",maxlength:"长度不能超过10" }
            ,B36EAD_TRADE_NAME: {maxlength:"长度不能超过50"}
            ,B36EAD_TRADE_CODE: {maxlength:"长度不能超过50"}
            ,B36EAD_TRADE_FILE: {maxlength:"长度不能超过50"}
			
            /*input check messages end*/
        },
        errorPlacement: function (error, element) {
            element.next().remove();
            element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
            element.closest('.form-group').append(error);
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error has-feedback');
        },
        success: function (label) {
            var el = label.closest('.form-group').find("input");
            el.next().remove();
            el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
            label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
            label.remove();
        },
        submitHandler: function (form) {
        	B36EAD_SubmitForm();
        	return false;
        }
    })
}